package cn.wit.test;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoCookie extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		Date date = new Date();
		
		DateFormat format = new SimpleDateFormat("yyyy-mm-dd/HH:mm:ss");
		
		//访问时间
		String dateformat =format.format(date);
		
		//取Cookie
//		Cookie[] cookie = req.getCookies();
		
		//创建一个Cookie
		Cookie cookie = new Cookie("accessDate", dateformat);
		cookie.setMaxAge(5);
		resp.addCookie(cookie);
		
		//让cookie持久化，存到文件中，下次启动，还是能正常启动
	
	}

}
